package fr.upmc.aladyn.manualreflect;

import fr.upmc.aladyn.shared.ObjectSingleton;
import fr.upmc.aladyn.annotation.Transactionable;

/**
 * Object class representing objects tagged with the 
 * <code>Transactionable</code> annotation. While in a transaction phase, if one
 * of the accessed field is a <code>Transactionable</code> Object, all of it's 
 * fields will be saved rather than just it's reference. This version is only 
 * used in the manual saving and restoration of transactions as it contains 
 * the code we are supposed to inject already
 * 
 * @author Thierry Wong
 * @author Seyyid ahmed Ouir
 */

@Transactionable
public class ObjetTrans 
{
	private int myValue;
	private String myName;
	
	/**
	 * Creates an instance of <code>ObjetTrans</code>. It is tagged with the 
	 * <code>Transactionable</code> annotation. 
	 * 
	 * By default, it is named "Toto" and has a value of 0.
	 */
	public ObjetTrans()
	{
		this.myName = "Toto";
		this.myValue = 0;
	}
	
	/**
	 * Creates an instance of <code>ObjetTrans</code>. It is tagged with the 
	 * <code>Transactionable</code> annotation. 
	 * 
	 * @param name Type <code>String</code> representing the name to be given
	 * @param value Type <code>int</code> representing the value to be given 
	 */
	public ObjetTrans(String name, int i)
	{
		this.myName = name;
		this.myValue = i;
	}
	
	/**
	 * Returns the value contained in this instance of <code>ObjetTrans</code> 
	 * 
	 * @return Type <code> int</code>  representing the value of the object
	 */
	public int getValue()
	{
		return this.myValue;
	}
	
	/**
	 * Affects a new value to this instance of <code> ObjetTrans </code> 
	 * 
	 * @param Type <code>int</code>  represents the new value to affect
	 */
	public void setValue(int newValue)
	{
		// In setter modifying Transactionable object, therefore we save 
		//**********************************
		ObjectSingleton.getInstance().sauvegarder(this);
		//**********************************
		
		this.myValue = newValue;
	}
	
	/**
	 * Returns the name of this instance of <code>ObjetTrans</code> 
	 * 
	 * @return Type <code>String</code> representing the name of the object
	 */
	public String getName()
	{
		return this.myName;
	}
	
	/**
	 * Affects a new name to this instance of <code>ObjetTrans</code> 
	 * 
	 * @param newName Type <code>String</code> represents the new name to affect
	 */
	public void setName(String name)
	{
		// In setter modifying Transactionable object, therefore we save 
		//**********************************
		ObjectSingleton.getInstance().sauvegarder(this);
		//**********************************		
		this.myName = name;
	}
}
